<template>
  <div class="pay-container">
    <h1>订单</h1>
    <div class="goods-price-box">
      <div>
        商品订单价格：
        <span class="goods-price">{{ goodsPrice }}</span>
        元
      </div>
    </div>
    <div class="pay-way">
      <div>选择支付方式</div>
      <div class="pay-way-list">
        <div :class="{ 'is-selected': payWay === 'wx' }" class="pay-way-list-item" @click="payWay = 'wx'">微信支付</div>
        <div :class="{ 'is-selected': payWay === 'zfb' }" class="pay-way-list-item" @click="payWay = 'zfb'">
          支付宝支付
        </div>
      </div>
      <div>已选择支付方式：{{ getPayWayText(payWay) }}</div>
    </div>
    <div class="btn-box">
      <el-button type="primary" @click="toSettle">去结算</el-button>
    </div>
  </div>
</template>

<!-- 安装vite-plugin-vue-setup-extend插件让<script setup>标签</script>可以直接自定义组件名 -->
<script setup lang="ts" name="OrderView">
const goodsPrice = ref(0.01)
const payWay = ref("wx")

const payWayMap: any = {
  wx: "微信",
  zfb: "支付宝",
}

const getPayWayText = (payWayType: string = "") => {
  if (payWayType === "") {
    return payWayType
  }
  return payWayMap[payWayType]
}
const toSettle = () => {
  console.log("去结算")
  console.log("已选择支付方式：", payWayMap[payWay.value])
  const params = {
    goodsPrice: goodsPrice.value,
    payWay: payWay.value,
  }
  console.log("params", params)
}
</script>

<style lang="scss" scoped>
.pay-container {
  padding: 20px;
  box-sizing: border-box;
  .goods-price-box {
    font-weight: 800;
    .goods-price {
      color: #ff0000;
    }
  }
  .pay-way {
    margin-top: 10px;
    .pay-way-list {
      padding: 10px 0;
      box-sizing: border-box;
      display: flex;
      flex-wrap: wrap;

      .pay-way-list-item {
        width: 200px;
        height: 100px;
        border: 4px solid #cccccc;
        border-radius: 4px;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      & > .pay-way-list-item:not(:first-child) {
        margin-left: 10px;
      }
      .is-selected {
        border: 4px solid #088ae7;
        color: #088ae7;
      }
    }
  }
  .btn-box {
    margin-top: 10px;
  }
}
</style>
